package com.shop2cn.sqpaygetway.testcase;

import java.math.BigDecimal;
import java.security.PrivateKey;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqpayment.parameter.AcquireOrderBean;
import com.shop2cn.iapi.sqpayment.parameter.AcquireRefundBean;
import com.shop2cn.iapi.sqpayment.parameter.RefundNotifyBean;
import com.shop2cn.sqpaygetway.parameter.ApplePayRefundNotifyBean;
import com.shop2cn.sqpaygetway.parameter.BaoFuRefundNotifyBean;
import com.shop2cn.sqpaygetway.parameter.BestPayRefundNotifyBean;
import com.shop2cn.sqpaygetway.parameter.SFTRefundNotifyBean;
import com.shop2cn.sqpaygetway.service.RefundNotifyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.core.tool.RSAUtils;
import com.ymt.util.DataManager;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.data.Sign;
import com.ymttest.business.data.applepaysign.ApplePayConstants;
import com.ymttest.business.data.applepaysign.Hex;
import com.ymttest.business.data.applepaysign.SecurityUtil;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.model.MRefund;
import com.ymttest.database.sqlwapper.SQPayGateWayWapper;
import com.ymttest.utils.BaofooSignature;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 退款回调 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_RefundNotify {
	private static RefundNotifyBean refundnotifyBean;
	private static RefundNotifyCall refundnotifyCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退款回调");
	}

	@Before
	public void caseUp() {
		refundnotifyBean = new RefundNotifyBean();
		refundnotifyCall = new RefundNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(refundnotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	// @Ignore
	public void Tc_RefundNotify_001() {
		Logger.start(true, "10支付宝PC支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("10");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			Logger.debug(SQPayGateWayCallService.getPaymentId(aqb));
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			refundnotifyBean = initRefundNotifyBean(aqb);
			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_002() {
		Logger.start(true, "13支付宝APP支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("13");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_003() {
		Logger.start(true, "11支付宝wap支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("11");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			refundnotifyBean = initRefundNotifyBean(aqb);
			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_RefundNotify_004() {
		Logger.start(true, "10支付宝PC支付同步回调重复回调,成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("10");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			pdw.updateRefundStatus(ar.getRefundNo(), "1");
			Logger.comment("查询PPPayment信息");
			MPayment ppm = new SQPayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);

			refundnotifyBean = initRefundNotifyBean(aqb);
			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);
			refundnotifyCall.addHeader("Mock", "1");
			refundnotifyCall.addHeader("MockResult-Trading-Status", "OK");
			refundnotifyCall.addHeader("MockResult-Trading-Body", "Proccessed");
			String mockResult = FormatUtil
					.urlEncode("is_success=T&result_details=" + ar.getRefundNo() + "^" + ppm.getInstitutionPaymentId() + "^" + aqb.getPayPrice() + "^SUCCESS");
			refundnotifyCall.addHeader("MockResult-AliPay-Result", mockResult);
			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_005() {
		Logger.start(true, "60ApplePay支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("60");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);
			refundnotifyCall.addHeader("MockResult-ApplePay-merId", SQPayGateWayCallService.APPLEPAY_MERID);
			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, applerfn);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_006() {
		Logger.start(true, "60ApplePay支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("60");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setSignature("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_007() {
		Logger.start(true, "60ApplePay支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("60");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_008() {
		Logger.start(true, "60ApplePay支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("60");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setOrderId("abc");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_009() {
		Logger.start(true, "60ApplePay支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("60");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);

			applerfn.setTxnAmt("1");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_RefundNotify_010() {
		//宝付退款渠道关闭,暂时没有记录
		Logger.start(true, "70宝付支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("70");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			BaoFuRefundNotifyBean baofurefundnbean = SQPayGateWayCallService.initBaoFuRefundNotifyBean(aqb);
			String baofuexecfund = FormatUtil.beanToGSONString(baofurefundnbean);
			Logger.debug("baofuexecfund:" + baofuexecfund);
			baofuexecfund = "data_content=" + new BaofooSignature().encryptData(baofuexecfund);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(baofuexecfund);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("OK", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, baofurefundnbean);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_011() {
		Logger.start(true, "70支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("70");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			BaoFuRefundNotifyBean baofurefundnbean = SQPayGateWayCallService.initBaoFuRefundNotifyBean(aqb);
			String baofuexecfund = FormatUtil.beanToGSONString(baofurefundnbean);
			Logger.debug("baofuexecfund:" + baofuexecfund);
			baofuexecfund = "data_content=1" + new BaofooSignature().encryptData(baofuexecfund);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(baofuexecfund);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_012() {
		Logger.start(true, "70支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("70");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			BaoFuRefundNotifyBean baofurefundnbean = SQPayGateWayCallService.initBaoFuRefundNotifyBean(aqb);
			baofurefundnbean.setMember_id("111");
			String baofuexecfund = FormatUtil.beanToGSONString(baofurefundnbean);
			Logger.debug("baofuexecfund:" + baofuexecfund);
			baofuexecfund = "data_content=" + new BaofooSignature().encryptData(baofuexecfund);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(baofuexecfund);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_013() {
		Logger.start(true, "70支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("70");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			BaoFuRefundNotifyBean baofurefundnbean = SQPayGateWayCallService.initBaoFuRefundNotifyBean(aqb);
			baofurefundnbean.setRefund_order_no("222");
			String baofuexecfund = FormatUtil.beanToGSONString(baofurefundnbean);
			Logger.debug("baofuexecfund:" + baofuexecfund);
			baofuexecfund = "data_content=" + new BaofooSignature().encryptData(baofuexecfund);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(baofuexecfund);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_014() {
		Logger.start(true, "70支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("70");
			aqb.setPayPrice("2.05");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			BaoFuRefundNotifyBean baofurefundnbean = SQPayGateWayCallService.initBaoFuRefundNotifyBean(aqb);
			baofurefundnbean.setRefund_amt(String.valueOf(Integer.valueOf(baofurefundnbean.getRefund_amt()) - 1));
			String baofuexecfund = FormatUtil.beanToGSONString(baofurefundnbean);
			Logger.debug("baofuexecfund:" + baofuexecfund);
			baofuexecfund = "data_content=" + new BaofooSignature().encryptData(baofuexecfund);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(baofuexecfund);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_015() {
		Logger.start(true, "9支付宝花呗支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("9");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	// @Ignore
	public void Tc_RefundNotify_016() {
		Logger.start(true, "80翼支付退款回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("80");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			Logger.debug(SQPayGateWayCallService.getPaymentId(aqb));
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
//			refundnotifyBean = initRefundNotifyBean(aqb);
//			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);
			BestPayRefundNotifyBean bestPayRefundNotifyBean=initRefundBestNotifyBean(aqb);
			String mac=signBestPayRefundNotify(bestPayRefundNotifyBean);
			bestPayRefundNotifyBean.setMac(mac);
			String send = FormatUtil.beanToHttpString(bestPayRefundNotifyBean, false);
			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals(bestPayRefundNotifyBean.getOurTransNo(), refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, bestPayRefundNotifyBean,4);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	// @Ignore
	public void Tc_RefundNotify_017() {
		Logger.start(true, "80翼支付退款金额错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("80");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			Logger.debug(SQPayGateWayCallService.getPaymentId(aqb));
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
//			refundnotifyBean = initRefundNotifyBean(aqb);
//			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);
			BestPayRefundNotifyBean bestPayRefundNotifyBean=initRefundBestNotifyBean(aqb);
			bestPayRefundNotifyBean.setTransAmt("1");
			String mac=signBestPayRefundNotify(bestPayRefundNotifyBean);
			bestPayRefundNotifyBean.setMac(mac);
			String send = FormatUtil.beanToHttpString(bestPayRefundNotifyBean, false);
			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	// @Ignore
	public void Tc_RefundNotify_018() {
		Logger.start(true, "80翼支付mac错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("80");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			Logger.debug(SQPayGateWayCallService.getPaymentId(aqb));
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
//			refundnotifyBean = initRefundNotifyBean(aqb);
//			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);
			BestPayRefundNotifyBean bestPayRefundNotifyBean=initRefundBestNotifyBean(aqb);
			String mac=signBestPayRefundNotify(bestPayRefundNotifyBean);
			bestPayRefundNotifyBean.setMac(mac+1);
			String send = FormatUtil.beanToHttpString(bestPayRefundNotifyBean, false);
			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	// @Ignore
	public void Tc_RefundNotify_019() {
		Logger.start(true, "80翼支付TransStatus为C失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("80");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			Logger.debug(SQPayGateWayCallService.getPaymentId(aqb));
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
//			refundnotifyBean = initRefundNotifyBean(aqb);
//			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);
			BestPayRefundNotifyBean bestPayRefundNotifyBean=initRefundBestNotifyBean(aqb);
			bestPayRefundNotifyBean.setTransStatus("C");
			String mac=signBestPayRefundNotify(bestPayRefundNotifyBean);
			bestPayRefundNotifyBean.setMac(mac);
			String send = FormatUtil.beanToHttpString(bestPayRefundNotifyBean, false);
			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals(bestPayRefundNotifyBean.getOurTransNo(), refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, bestPayRefundNotifyBean,-1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	// @Ignore
	public void Tc_RefundNotify_020() {
		Logger.start(true, "80翼支付MerchantCode错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("80");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			Logger.debug(SQPayGateWayCallService.getPaymentId(aqb));
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
//			refundnotifyBean = initRefundNotifyBean(aqb);
//			String send = aliPayRefundNotifyToSend(refundnotifyBean, aqb);
			BestPayRefundNotifyBean bestPayRefundNotifyBean=initRefundBestNotifyBean(aqb);
			bestPayRefundNotifyBean.setMerchantCode("1");
			String mac=signBestPayRefundNotify(bestPayRefundNotifyBean);
			bestPayRefundNotifyBean.setMac(mac);
			String send = FormatUtil.beanToHttpString(bestPayRefundNotifyBean, false);
			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_021() {
		Logger.start(true, "62upay-app支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("62");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);
			refundnotifyCall.addHeader("MockResult-ApplePay-merId", SQPayGateWayCallService.APPLEPAY_MERID);
			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, applerfn);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_022() {
		Logger.start(true, "62upay-app支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("62");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setSignature("123");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_023() {
		Logger.start(true, "62upay-app支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("62");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_024() {
		Logger.start(true, "62upay-app支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("62");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setOrderId("abc");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_025() {
		Logger.start(true, "62upay-app支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("62");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			applerfn.setTxnAmt("1");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_026() {
		Logger.start(true, "63upay-WAP支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("63");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);
			refundnotifyCall.addHeader("MockResult-ApplePay-merId", SQPayGateWayCallService.APPLEPAY_MERID);
			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, applerfn);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_027() {
		Logger.start(true, "63upay-WAP支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("63");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setSignature("123");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_028() {
		Logger.start(true, "63upay-WAP支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("63");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_029() {
		Logger.start(true, "63upay-WAP支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("63");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setOrderId("abc");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_030() {
		Logger.start(true, "63upay-WAP支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("63");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			applerfn.setTxnAmt("1");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_031() {
		Logger.start(true, "64小米支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("64");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);
			refundnotifyCall.addHeader("MockResult-ApplePay-merId", SQPayGateWayCallService.APPLEPAY_MERID);
			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, applerfn);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_032() {
		Logger.start(true, "64小米支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("64");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setSignature("123");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_033() {
		Logger.start(true, "64小米支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("64");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_034() {
		Logger.start(true, "64小米支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("64");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setOrderId("abc");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_035() {
		Logger.start(true, "64小米支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("64");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			applerfn.setTxnAmt("1");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_036() {
		Logger.start(true, "3013支付宝APP支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("3013");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_037() {
		Logger.start(true, "65.HuaweiPay支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("65");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);
			refundnotifyCall.addHeader("MockResult-ApplePay-merId", SQPayGateWayCallService.APPLEPAY_MERID);
			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, applerfn);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_038() {
		Logger.start(true, "65.HuaweiPay支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("65");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setSignature("123");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_039() {
		Logger.start(true, "65.HuaweiPay支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("65");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_040() {
		Logger.start(true, "65.HuaweiPay支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("65");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setOrderId("abc");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_041() {
		Logger.start(true, "65.HuaweiPay支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("65");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			applerfn.setTxnAmt("1");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_042() {
		Logger.start(true, "66.SamSungPay支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("66");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);
			refundnotifyCall.addHeader("MockResult-ApplePay-merId", SQPayGateWayCallService.APPLEPAY_MERID);
			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, applerfn);
			SQPayGateWayWapper pdw = new SQPayGateWayWapper();
			List<MRefund> list = pdw.selectRefundRequestByTraceId(ar.getRefundNo());
			Logger.verifyEquals(4, list.get(0).getRefundStatus(), "交易网关返回退款成功RefundStatus4");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_043() {
		Logger.start(true, "66.SamSungPay支付同步回调签名错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("66");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setSignature("123");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_044() {
		Logger.start(true, "66.SamSungPay支付同步回调MerId错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("66");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId("123");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_045() {
		Logger.start(true, "66.SamSungPay支付同步回调退款批次不存在错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("66");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setOrderId("abc");
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_046() {
		Logger.start(true, "66.SamSungPay支付同步回调金额不匹配错误失败");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("66");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
				SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			ApplePayRefundNotifyBean applerfn = initApplePayRefundNotifyBean(aqb);
			applerfn.setMerId(SQPayGateWayCallService.UPAY_MERID);
			applerfn.setTxnAmt("1");
			String send = applePayRefundNotifyToSend(applerfn, aqb);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_047() {
		Logger.start(true, "8支付宝花呗支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("8");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_048() {
		Logger.start(true, "3113支付宝APP支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("3113");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_049() {
		Logger.start(true, "3213支付宝APP支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("3213");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_050() {
		Logger.start(true, "2013支付宝APP支付同步回调成功");
		try {
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("2013");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());

			refundnotifyBean = initRefundNotifyBean(aqb);

			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundnotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundnotifyBean.setSign(sign);
			refundnotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			String send = FormatUtil.beanToHttpString(refundnotifyBean, true);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("success", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundnotifyBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_051() {
		Logger.start(true, "6010盛付通支付同步回调成功");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6010");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			String refundamt=new BigDecimal(aqb.getPayPrice()).setScale(2).toString();
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, refundamt);
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,refundamt);
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("OK", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundbn);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_052() {
		Logger.start(false, "6010盛付通支付同步回调-金额不正确失败");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6010");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			String refundamt=new BigDecimal(aqb.getPayPrice()).setScale(2).toString();
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, refundamt);
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,1+refundamt);
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
			List<MRefund> rmrl = new SQPayGateWayWapper().selectRefundRequestByRefundBatchNo(refundbn);
//			Logger.debug(FormatUtil.beanToGSONString(rmrl));
			Logger.verifyEquals(0, rmrl.get(0).getRefundStatus(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_053() {
		Logger.start(false, "6010盛付通支付同步回调-status不正确失败");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6010");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			String refundamt=new BigDecimal(aqb.getPayPrice()).setScale(2).toString();
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, refundamt);
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,refundamt);
			 initSFTRefundSend.setStatus("02");
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			//这里只看status  返回成功给第三方
			Logger.verifyEquals("OK", refundnotifyCall.getReturnData(), "验证返回");
			List<MRefund> rmrl = new SQPayGateWayWapper().selectRefundRequestByRefundBatchNo(refundbn);
//			Logger.debug(FormatUtil.beanToGSONString(rmrl));
			Logger.verifyEquals(-1, rmrl.get(0).getRefundStatus(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_054() {
		Logger.start(false, "6010盛付通支付同步回调-paymentid不正确失败");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6010");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,aqb.getPayPrice());
			 initSFTRefundSend.setOriginalOrderNo(ppm.getPaymentId()+1);
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
			List<MRefund> rmrl = new SQPayGateWayWapper().selectRefundRequestByRefundBatchNo(refundbn);
//			Logger.debug(FormatUtil.beanToGSONString(rmrl));
			Logger.verifyEquals(0, rmrl.get(0).getRefundStatus(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_055() {
		Logger.start(false, "6010盛付通支付同步回调-refundbn不正确失败");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6010");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, aqb.getPayPrice());
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,aqb.getPayPrice());
			 initSFTRefundSend.setRefundOrderNo(refundbn+1);
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("fail", refundnotifyCall.getReturnData(), "验证返回");
			List<MRefund> rmrl = new SQPayGateWayWapper().selectRefundRequestByRefundBatchNo(refundbn);
//			Logger.debug(FormatUtil.beanToGSONString(rmrl));
			Logger.verifyEquals(0, rmrl.get(0).getRefundStatus(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_056() {
		Logger.start(true, "6011盛付通支付同步回调成功");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6011");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			String refundamt=new BigDecimal(aqb.getPayPrice()).setScale(2).toString();
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, refundamt);
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,refundamt);
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("OK", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundbn);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_RefundNotify_057() {
		Logger.start(true, "6012盛付通支付宝支付同步回调成功");
		try {
			SQPayGateWayWapper pdw=new SQPayGateWayWapper();
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6012");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			String refundamt=new BigDecimal(aqb.getPayPrice()).setScale(2).toString();
			AcquireRefundBean ar = SQPayGateWayCallService.AcquireRefund(aqb, refundamt);
			SQPayGateWayCallService.approveRefund(ar.getTradeNo());
			MPayment ppm = SQPayGateWayCallService.getPPayment(aqb);
			MRefund mrr = pdw.selectRefundRequestByPaymentId(ppm.getPaymentId()).get(0);
			String refundbn = mrr.getRefundBatchNo().toString();
			String refundid = mrr.getRefundId().toString();
			pdw.updateRefundStatus(refundbn, "0");
			
			// 转换成最终发出的数据
			 SFTRefundNotifyBean initSFTRefundSend =SQPayGateWayCallService.initSFTRefundSend(ppm,refundbn,refundamt);
			String send = SQPayGateWayCallService.SFTRefundPayNotifyBeanToSend(initSFTRefundSend);

			refundnotifyCall = new RefundNotifyCall(aqb.getPayType());
			refundnotifyCall.setData(send);

			refundnotifyCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			refundnotifyCall.addHeader("MockId", mockid);

			Logger.comment("添加Mock:" + mockid);

			refundnotifyCall.callService();
			Logger.verifyEquals("OK", refundnotifyCall.getReturnData(), "验证返回");
			verifyDB(aqb, refundbn);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyDB(AcquireOrderBean aqb, BestPayRefundNotifyBean bestPayRefundNotifyBean,Integer status) throws InterruptedException {
		Logger.comment("验证数据库refundlog");
		SQPayGateWayWapper pg = new SQPayGateWayWapper();
		String batchno = bestPayRefundNotifyBean.getRefundReqNo();
		List<MRefund> rmrl = pg.selectRefundRequestByRefundBatchNo(batchno);
		Logger.verifyEquals(status,rmrl.get(0).getRefundStatus(),"验证status");
		Logger.debug("rmrl:" + FormatUtil.beanToGSONString(rmrl));
		String reqid = rmrl.get(0).getRefundId().toString();
		List<Map> list = pg.selectRefundMiscRequestLogByRefundId(reqid);
		Logger.debug("refundlog:" + FormatUtil.beanToGSONString(list));
		Logger.verifyEquals(true, list.size()>=1, "验证记录");
		
	}

	/**
	 * @param aqb
	 * @param ar
	 * @return
	 * @throws InterruptedException
	 */
	private BestPayRefundNotifyBean initRefundBestNotifyBean(AcquireOrderBean aqb) throws InterruptedException {
		BestPayRefundNotifyBean bestPayRefundNotifyBean=new BestPayRefundNotifyBean();
		bestPayRefundNotifyBean.setMerchantCode(SQPayGateWayCallService.BESTPAY_MERID);
		MPayment ppm = new SQPayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		MRefund RefundRequest = new SQPayGateWayWapper().selectRefundRequestByPaymentid(ppm.getPaymentId()).get(0);
		
		bestPayRefundNotifyBean.setOldOrderNo(ppm.getPaymentId());
		bestPayRefundNotifyBean.setOldOrderReqNo(ppm.getPaymentId());
		bestPayRefundNotifyBean.setOurTransNo(TestDataManager.getRandomUUID().toString());
		bestPayRefundNotifyBean.setRefundReqNo(RefundRequest.getRefundBatchNo());
		bestPayRefundNotifyBean.setTransAmt(String.valueOf(RefundRequest.getRefundAmt().multiply(new BigDecimal(100)).intValue()));
		bestPayRefundNotifyBean.setTransStatus("B");
		
		return bestPayRefundNotifyBean;
	}
	/**
	 * 退款回调加签
	 * @param bestPayRefundNotifyBean
	 * @return
	 */
	private String signBestPayRefundNotify(BestPayRefundNotifyBean bestPayRefundNotifyBean){
//		MERCHANTCODE=4401000041&OLDORDERNO=16091310313809288961&
//		OLDORDERREQNO=16091310313809288961000001&OURTRANSNO=2016091300000667874366&
//		REFUNDREQNO=16091310313809288961000002&TRANSAMT=1&TRANSSTATUS=B&KEY=67B6A6362B7C80E9
		
		StringBuffer source=new StringBuffer();
		source.append("MERCHANTCODE=");
		source.append(bestPayRefundNotifyBean.getMerchantCode());
		source.append("&OLDORDERNO=");
		source.append(bestPayRefundNotifyBean.getOldOrderNo());
		source.append("&OLDORDERREQNO=");
		source.append(bestPayRefundNotifyBean.getOldOrderReqNo());
		source.append("&OURTRANSNO=");
		source.append(bestPayRefundNotifyBean.getOurTransNo());
		source.append("&REFUNDREQNO=");
		source.append(bestPayRefundNotifyBean.getRefundReqNo());
		source.append("&TRANSAMT=");
		source.append(bestPayRefundNotifyBean.getTransAmt());
		source.append("&TRANSSTATUS=");
		source.append(bestPayRefundNotifyBean.getTransStatus());
		source.append("&KEY=");
		source.append(SQPayGateWayCallService.autoTestKey);
		String mac = TestDataManager.getMD5(source.toString().getBytes()).replace("-", "");
		return mac;
	}

	private String applePayRefundNotifyToSend(ApplePayRefundNotifyBean applerfb, AcquireOrderBean aqb) throws Exception {
		// TODO Auto-generated method stub
		String plaintext = FormatUtil.beanToHttpString(applerfb, false);
		byte[] signDigest = SecurityUtil.sha1(plaintext, ApplePayConstants.encoding);
		signDigest = Hex.toHexBytes(signDigest, ApplePayConstants.encoding);
		PrivateKey privateKey = RSAUtils.loadPrivateKey(EnvSetup.getData("privateK"));
		byte[] signData = SecurityUtil.signWithSha1Rsa(privateKey, signDigest);
		signData = Base64.getEncoder().encode(signData);
		applerfb.setSignature(new String(signData));
		String send = FormatUtil.beanToHttpString(applerfb, true);
		return send;
	}

	private ApplePayRefundNotifyBean initApplePayRefundNotifyBean(AcquireOrderBean aqb) throws InterruptedException {
		ApplePayRefundNotifyBean aprf = new ApplePayRefundNotifyBean();
		Integer price = new BigDecimal(aqb.getPayPrice()).multiply(new BigDecimal(100)).intValue();
		MPayment ppm = new SQPayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		MRefund RefundRequest = new SQPayGateWayWapper().selectRefundRequestByPaymentid(ppm.getPaymentId()).get(0);
		aprf.setCurrencyCode("156");
		aprf.setMerId(SQPayGateWayCallService.APPLEPAY_MERID);
		aprf.setOrderId(RefundRequest.getRefundBatchNo());
		aprf.setRespCode("00");
		aprf.setTxnAmt(price.toString());
		return aprf;
	}

	private RefundNotifyBean initRefundNotifyBean(AcquireOrderBean aqb) throws Exception {
		refundnotifyBean.setNotify_time(DataManager.getSysTime());
		refundnotifyBean.setNotify_type("batch_refund_notify");
		refundnotifyBean.setNotify_id(TestDataManager.getClientpaymentId());
		try {
			MPayment ppm = new SQPayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			MRefund RefundRequest = new SQPayGateWayWapper().selectRefundRequestByPaymentid(ppm.getPaymentId()).get(0);
			String result_details = ppm.getInstitutionPaymentId() + "^" + aqb.getPayPrice() + "^SUCCESS" + "$"+SQPayGateWayCallService.Alipay_EMAIL+"^"+SQPayGateWayCallService.Alipay_MERID+"^0.01^SUCCESS";
			if(aqb.getPayType().equals("3113")) {
				result_details = ppm.getInstitutionPaymentId() + "^" + aqb.getPayPrice() + "^SUCCESS" + "$"+SQPayGateWayCallService.Alipay_EMAIL_Could+"^"+SQPayGateWayCallService.Alipay_MERID_Could+"^0.01^SUCCESS";
			}
			refundnotifyBean.setResult_details(result_details);
			refundnotifyBean.setBatch_no(RefundRequest.getRefundBatchNo());
			refundnotifyBean.setSuccess_num("1");
		} catch (Exception e) {
			Logger.debug(e.getMessage());
		}
		return refundnotifyBean;
	}

	private String aliPayRefundNotifyToSend(RefundNotifyBean refundNotifyBean, AcquireOrderBean aqb) throws Exception {
		Logger.comment("aliPayRefundNotify加签并转换为SendString");
		String send = null;
		if (aqb.getPayType().equals("13")) {
			// 排序加签名
			String src = FormatUtil.beanToHttpString(refundNotifyBean, false);
			String sign = new Sign().SignSHA1WithRSA(src);
			refundNotifyBean.setSign(sign);
			refundNotifyBean.setSign_type("RSA");
			// 转换成最终发出的数据
			send = FormatUtil.beanToHttpString(refundNotifyBean, true);
		} else {
			String src = FormatUtil.beanToHttpString(refundNotifyBean, false);
			String sign = new Sign().signMd5(refundNotifyBean, Sign.autoTestKey);
			refundNotifyBean.setSign(sign);
			refundNotifyBean.setSign_type("MD5");
			send = FormatUtil.beanToHttpString(refundNotifyBean, true);
		}
		return send;
	}

	private void verifyDB(AcquireOrderBean aqb, RefundNotifyBean refundnotifyBean) throws Exception {
		Logger.comment("验证数据库refundlog");
		SQPayGateWayWapper pg = new SQPayGateWayWapper();
		String batchno = refundnotifyBean.getBatch_no();
		List<MRefund> rmrl = pg.selectRefundRequestByRefundBatchNo(batchno);
		String reqid = rmrl.get(0).getRefundId().toString();
		List<Map> list = pg.selectRefundMiscRequestLogByRefundId(reqid);
		Logger.debug("refundlog:" + FormatUtil.beanToGSONString(list));
		Logger.verifyEquals(true, list.size()>=1, "验证记录");

	}
	private void verifyDB(AcquireOrderBean aqb, String batchno) throws Exception {
		Logger.comment("验证数据库refundlog");
		SQPayGateWayWapper pg = new SQPayGateWayWapper();
		List<MRefund> rmrl = pg.selectRefundRequestByRefundBatchNo(batchno);
//		Logger.debug(FormatUtil.beanToGSONString(rmrl));
		Logger.verifyEquals(4, rmrl.get(0).getRefundStatus(), "验证status");
		String reqid = rmrl.get(0).getRefundId().toString();
		List<Map> list = pg.selectRefundMiscRequestLogByRefundId(reqid);
		Logger.debug("refundlog:" + FormatUtil.beanToGSONString(list));
		Logger.verifyEquals(true, list.size()>=1, "验证记录");

	}
	private void verifyDB(AcquireOrderBean aqb, ApplePayRefundNotifyBean applepayref) throws Exception {
		Logger.comment("验证数据库refundlog");
		SQPayGateWayWapper pg = new SQPayGateWayWapper();
		String batchno = applepayref.getOrderId();
		List<MRefund> rmrl = pg.selectRefundRequestByRefundBatchNo(batchno);
		String reqid = rmrl.get(0).getRefundId().toString();
		List<Map> list = pg.selectRefundMiscRequestLogByRefundId(reqid);
		Logger.debug("refundlog:" + FormatUtil.beanToGSONString(list));
		Logger.verifyEquals(true, list.size()>=1, "验证记录");
	}

	private void verifyDB(AcquireOrderBean aqb, BaoFuRefundNotifyBean refundnotifyBean) throws Exception {
		Logger.comment("验证数据库refundlog");
		SQPayGateWayWapper pg = new SQPayGateWayWapper();
		String batchno = refundnotifyBean.getRefund_order_no();
		List<MRefund> rmrl = pg.selectRefundRequestByRefundBatchNo(batchno);
		String reqid = rmrl.get(0).getRefundId().toString();
		List<Map> list = pg.selectRefundMiscRequestLogByRefundId(reqid);
		Logger.debug("refundlog:" + FormatUtil.beanToGSONString(list));
		Logger.verifyEquals(true, list.size()>=1, "验证记录");

	}
}
